﻿using System.Collections.Generic;
using System.Reflection;
using System.Linq;

namespace InnovTech.Data.NHibernate
{
    public class MappingFileAssembly
    {
        /// <summary>
        /// Gets or sets the assembly name of this mapping file but without the file extension, like .DLL or .EXE
        /// </summary>
        public string AssemblyName { get; set; }

        public List<MappingFile> MappingFiles { get; private set; }

        public MappingFileAssembly(string assemblyName, params string[] filePaths)
        {
            AssemblyName = assemblyName;
            MappingFiles = new List<MappingFile>();
            AddMappingFile(filePaths);
        }

        public void AddMappingFile(params string[] filePaths)
        {
            if (filePaths != null)
            {
                foreach (var filePath in filePaths)
                {
                    MappingFiles.Add(new MappingFile(AssemblyName, filePath));
                }
            }
        }

        public IEnumerable<string> GetMappingFiles()
        {
            var mappingFiles = from mf in MappingFiles
                               select mf.FilePath;
            return mappingFiles;
        }

        public Assembly GetAssembly()
        {
            return Assembly.Load(AssemblyName);
        }
    }
}
